import time
import mss
import cv2
import numpy as np
import os
import sys
from pathlib import Path

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0]  # YOLOv5 root directory
if str(ROOT) not in sys.path:
    sys.path.append(str(ROOT))  # add ROOT to PATH
ROOT = Path(os.path.relpath(ROOT, Path.cwd()))  # relative

path = ROOT / "YOLO_CS16\\temp\\images\\"
name = ""

fource = cv2.VideoWriter_fourcc(*'XVID')
size = (800,600)

cnt = 0
delay = 1

sct = mss.mss()
monitor = {"top": 130, "left": 450, "width": 1024, "height": 768}
time.sleep(10)

date = time.strftime('%Y-%m-%d', time.localtime(time.time()))
for file in os.listdir(path):
    if date in file:
        cnt += 1
while(True):
    time.sleep(delay)
    cnt+=1
    img= np.array(sct.grab(monitor))
    num = str(cnt)
    name = str(path / (time.strftime('%Y-%m-%d', time.localtime(time.time())) + num + ".jpg" ))
    print(name)
    cv2.imwrite(name, img)
